package com.service.impl;

import com.dao.impl.UserDaoImpl;
import com.dao.intf.UserDao;
import com.entity.Relation;
import com.entity.User;
import com.service.intf.UserService;

import java.util.List;

public class UserServiceImpl implements UserService {
    private UserDao userDao=new UserDaoImpl();

    @Override
    public List<User> queryUserByRoleAdmin() {
        return userDao.queryUserByRoleAdmin();
    }

    @Override
    public User queryUserByUsername(String username) {
        return userDao.queryUserByUsername(username);
    }

    @Override
    public void registerUser(User user) {
        userDao.saveUser(user);
    }

    @Override
    public User login(User user) {

        return userDao.queryUserByUsernameAndPassword(user.getUsername(),user.getPassword());

    }

    @Override
    public boolean existsUsername(String username) {
        if(userDao.queryUserByUsername(username)==null){
            //等于null，说明没查到，没查到表示可用
            return false;
        }
        return true;
    }



    @Override
    public List<Relation> queryFollowerName(String username) {
        return userDao.queryFollowerName(username);
    }

    @Override
    public Integer queryFollowerNum(String username) {
        return userDao.queryFollowerNum(username);
    }

    @Override
    public List<Relation> queryFollowedName(String username) {
        return userDao.queryFollowedName(username);
    }

    @Override
    public Integer queryFollowedNum(String username) {
        return userDao.queryFollowedNum(username);
    }

    @Override
    public void addFollower(String followerName, String followedName) {
        userDao.addFollower(followerName,followedName);
    }

    @Override
    public void deleteFollower(String followerName, String followedName) {
        userDao.deleteFollower(followerName,followedName);
    }

    @Override
    public boolean isFollower(String followerName, String followedName) {
        return userDao.isFollower(followerName,followedName);
    }

    @Override
    public List<User> queryIsFreezedUser() {
        return userDao.queryIsFreezedUser();
    }

    @Override
    public void setIsFreezed(Integer userId) {
         userDao.setIsFreezed(userId);
    }

    @Override
    public void deleteIsFreezed(Integer userId) {
         userDao.deleteIsFreezed(userId);
    }

    @Override
    public void updateUserNameAndPassword(String userName, String originalUserName, String passWord) {
        userDao.updateUserNameAndPassword(userName,originalUserName,passWord);
    }
}